import http from "../uitls/http.js";

// 获取分类信息
export const getCategoriesAPI = () => {
  return http({
    url: "/categories/get",
  });
};

// 新增文章
export const addArticleAPI = (data) => {
  return http({
    url: "/article/add",
    method: "post",
    data,
  });
};

// 获取文章列表
export const getArticleListAPI = ({current, pageSize=7, dateFrom='',dateTo='', category='', keyword=''}) => {
  return http({
    url: "/article/list",
    params:{ 
      current, 
      pageSize, 
      dateFrom, 
      dateTo,
      category, 
      keyword
    },
    method: "get",
  });
};

// 根据id获取文章
export const getArticleAPI = (id) => {
  return http({
    url: "/article/get",
    params: {
      articleId: id,
    },
    method: "get",
  });
};

// 根据分类id获取该分类下的所有文章id和标题
export const getSimpleArticlesByCategoryIdAPI = (categoryId) => {
  return http({
    url: "/categories/getArticles",
    params: {
      categoryId
    },
    method: "get",
  });
};

// 根据分类id修改分类名称
export const updateCategoryNameByIdAPI = (categoryId, newName) => {
  return http({
    url: "/categories/put",
    params: {
      categoryId,
      newName
    },
    method: "put",
  });
};

// 获取分页标签
export const getTagListAPI = (params) => {
  return http({
    url: "/tags/list",
    method: "get",
    params
  });
};

// 获取所有标签
export const getAllTagAPI = () => {
  return http({
    url: "/tags/all",
    method: "get",
  });
};

// 根据标签id获取该标签下的所有文章id和标题
export const getSimpleArticlesByTagIdAPI = (tagId) => {
  return http({
    url: "/tags/getArticles",
    params: {
      tagId
    },
    method: "get",
  });
};

// 根据标签id修改标签名称
export const updateTagNameByIdAPI = (tagId, newName) => {
  return http({
    url: "/tags/put",
    params: {
      tagId,
      newName
    },
    method: "put",
  });
};

// 根据标签id删除标签
export const deleteTagByIdAPI = (tagId) => {
  return http({
    url: "/tags/delete",
    params: {
      tagId
    },
    method: "delete",
  });
};

// 用户端获取文章列表
export const getContentListApi = (current, categoryName) => {
  return http({
    url: "/article/content",
    params: {
      current,
      categoryName
    }
  });
};

// 根据id获取前端详细文章
export const getDetailArticleAPI = (id) => {
  return http({
    url: "/article/detail",
    params: {
      articleId: id,
    },
    method: "get",
  });
};

// 父分类id新增分类名称
export const addCategoryAPI = (name, parentId) => {
  return http({
    url: "/categories/add",
    params: {
      name,
      parentId
    },
    method: "post",
  });
};

// 请求文章数量, 分类数量和标签数量
export const getSiteStateAPI = () => {
  return http({
    url: "/article/state",
  });
};

// 获取图片验证码
export const getCodeAPI = () => {
  return http({
    url: "/code",
  });
};

// 登录
export const loginAPI = (data) => {
  return http({
    url: "/login",
    method:'post',
    data
  });
};

// 获取关于我的id 
export const getAboutMeAPI = () => {
  return http({
    url: "/article/about",
  });
};

// 获取网站预览信息
export const getPreviewAPI = () => {
  return http({
    url: "/web/preview",
  });
};

// 获取网站预览信息
export const searchApi = (params) => {
  return http({
    url: "/search",
    method:'post',
    params
  });
};

// 获取网站setting信息
export const getSettingAPI = () => {
  return http({
    url: "/setting/get",
  });
};

// 获取网站setting信息
export const updateSettingAPI = (params) => {
  return http({
    url: "/setting/post",
    method:'post',
    params
  });
};

// 退出登录
export const logoutAPI = () => {
  return http({
    url: "/logout",
  });
};